package org.compiere.model;

import java.util.logging.Level;

/**
 * 数据同步
 * @author Administrator
 *
 */
public class POXML {
	
	public static final Object get_Value (Object[] m_newValues, Object[] m_oldValues, int index)
	{
		
		if (m_newValues[index] != null)
		{
			if (m_newValues[index].equals(Null.NULL))
				return null;
			return m_newValues[index];
		}
		return m_oldValues[index];
	}   //  get_Value
	
	
	public static String getXML(POInfo	p_info, Object[] m_newValues, Object[] m_oldValues) {
		StringBuffer sbf = new StringBuffer();
		StringBuffer sbfValue = new StringBuffer();
		int size = p_info.getColumnCount();
		boolean comma = true;
		sbf.append("<TABLE border=\"1\" operation=\"insert\" name=\"");
		sbf.append(p_info.getTableName());
		sbf.append("\">");
		sbf.append("<TR>");
		sbfValue.append("<TR>");
		for (int i = 0; i < size; i++)
		{
			Object value = get_Value(m_newValues, m_oldValues, i);		
			if (value == null || p_info.isVirtualColumn(i)) {
				continue;
			}
			String columnName = p_info.getColumnName(i);
			sbf.append("<TD>");
			sbf.append(columnName);
			sbf.append("</TD>");			
			sbfValue.append("<TD>");
			sbfValue.append(value.toString());
			sbfValue.append("</TD>");
					
			
			
		}
		sbfValue.append("</TR>");
		sbf.append("</TR>");
		sbf.append(sbfValue);
		
		sbf.append("</TABLE>");
		return sbf.toString();
		
	}
	
	public static String getXMLUpdate(POInfo	p_info, Object[] m_newValues, Object[] m_oldValues) {
		StringBuffer sbf = new StringBuffer();
		StringBuffer sbfValue = new StringBuffer();
		int size = p_info.getColumnCount();
		boolean comma = true;
		sbf.append("<TABLE border=\"1\" operation=\"update\" name=\"");
		sbf.append(p_info.getTableName());
		sbf.append("\">");
		sbf.append("<TR>");
		sbfValue.append("<TR>");
		for (int i = 0; i < size; i++)
		{
			Object value = get_Value(m_newValues, m_oldValues, i);		
			if (value == null || p_info.isVirtualColumn(i)) {
				continue;
			}
			String columnName = p_info.getColumnName(i);
			sbf.append("<TD>");
			sbf.append(columnName);
			sbf.append("</TD>");			
			sbfValue.append("<TD>");
			sbfValue.append(value.toString());
			sbfValue.append("</TD>");
					
			
			
		}
		sbfValue.append("</TR>");
		sbf.append("</TR>");
		sbf.append(sbfValue);
		
		sbf.append("</TABLE>");
		return sbf.toString();
		
	}
	
}
